import React, { useState, useEffect } from 'react'
import styles from '../../style/childPublic/childPublic.module.less'
import conBack from '../../style/contentBack/contentBack.module.less'
import { Timeline, Button, message } from 'antd';
import HeaderTop from "../../components/HeaderTop/HeaderTop";
import { pubLishList } from '../../apis/policyInformation'

export default function LawEnforcementSupervision() {
  const [messageApi, contextHolder] = message.useMessage();
  const key = 'updatable';
  const [title] = useState('农药技术信息发布管理')
  const [mode, setMode] = useState('left');
  const [list, setList] = useState([
    {
      label: '2015-09-01',
      children: 'Create a 1',
    }
  ])
  const onChange = (e) => {
    setMode(e.target.value);
  };
  useEffect(() => {
    pubLish()
  }, []);
  // 信息发布管理列表
  const pubLish = async () => {
    messageApi.open({
      key,
      type: 'loading',
      content: '数据加载中...',
    });
    const { data } = await pubLishList({ type: 4, xian_id: localStorage.getItem('areaId') })
    if (data.state === 1) {
      const newArray = []
      data.list.forEach(item => {
        newArray.push({ label: item.create_time_str, children: item.name })
      })
      setList(newArray)
      messageApi.open({
        key,
        type: 'success',
        content: '数据加载完成!',
        duration: 2,
      });
    } else {
      messageApi.open({
        key,
        type: 'error',
        content: data.msg,
        duration: 2,
      });
    }
  }
  return (
    <div div className={styles.pubBack}>
      {contextHolder}
      <HeaderTop title={title}></HeaderTop>
      <div className={conBack.contentBack}>
        <span className={conBack.topTitle}>信息发布管理列表</span>
        <div className={conBack.timeBox}>
          <div className={conBack.butAdd}>
            <Button type="primary">新增</Button>
          </div>
          <div className={conBack.timeLine}>
            <Timeline
              mode={mode}
              items={list}
            />
          </div>
        </div>

      </div>
    </div>
  )
}
